package com.newgrand.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.newgrand.mapper.SecDevMdmContractMapper;
import com.newgrand.model.SecDevMdmContract;
import com.newgrand.utils.uuid.GetNewPhidUtils;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhanglixin
 * @Data: 2023/6/10 22:34
 * @Description: TODO
 */

@Component
public class ContractMQ {

    @Autowired
    private UipLog uipLog;

    @Autowired
    private SecDevMdmContractMapper secDevMdmContractMapper;



    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "contract.info.ng"),
            exchange = @Exchange(name = "contract-exchange", type = ExchangeTypes.TOPIC),
            key = "#.info"
    ))
    public void process(String msg, Message message,Channel channel) {
        try {
            uipLog.info("contract","接收到合同","11111");
            uipLog.info("contract","接收到合同",msg);
            Date now = new Date();
            //存入中间表
            String phid = GetNewPhidUtils.getPhid();
            SecDevMdmContract secDevMdmContract = SecDevMdmContract.builder()
                    .phid(phid).contract(msg).ngInsertDt(now)
                    .build();
            secDevMdmContractMapper.insert(secDevMdmContract);




        }catch (Exception ex){
            uipLog.error("contract","接收到合同异常",ex.getMessage());
        }
    }

}

